package leetcode1;

// 169. 多数元素
public class leetcode169 {
    class Solution {
        public int majorityElement(int[] nums) {
            //正负离子思想
            int target=0;
            int count=0;
            for (int i = 0; i < nums.length; i++) {
                if(count==0){
                    target=nums[i];
                }
                if (target==nums[i]){
                    count++;
                }else {
                    //说明此数与当前正离子不相等，为负离子，正负中和-1
                    count--;
                }
            }
            return  target;
        }
    }
}
